home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / daemons / ipServer / tcpInt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-16  |  8.6 KB  |  261 lines

  1. /*
  2.  * tcpInt.h --
  3.  *
  4.  *    Internal declarations of data structures for handling the TCP protocol.
  5.  *    The data structures in this file are based on the functional
  6.  *    specification of the Transmission Control Protocol in RFC 793
  7.  *    (Sept. 1981).
  8.  *
  9.  *    Based on the following 4.3BSD files:
  10.  *      "@(#)tcp_fsm.h   7.2 (Berkeley) 12/7/87"
  11.  *      "@(#)tcp_seq.h   7.2 (Berkeley) 12/7/87"
  12.  *      "@(#)tcp_var.h   7.7 (Berkeley) 2/27/88"
  13.  *      "@(#)tcp_debug.h 7.2 (Berkeley) 12/7/87"
  14.  *
  15.  * Copyright 1987 Regents of the University of California
  16.  * All rights reserved.
  17.  * Permission to use, copy, modify, and distribute this
  18.  * software and its documentation for any purpose and without
  19.  * fee is hereby granted, provided that the above copyright
  20.  * notice appear in all copies.  The University of California
  21.  * makes no representations about the suitability of this
  22.  * software for any purpose.  It is provided "as is" without
  23.  * express or implied warranty.
  24.  *
  25.  *
  26.  * $Header: /sprite/src/daemons/ipServer/RCS/tcpInt.h,v 1.5 89/08/15 19:55:49 rab Exp $ SPRITE (Berkeley)
  27.  */
  28.  
  29. #ifndef _IPS_TCPINT
  30. #define _IPS_TCPINT
  31.  
  32. #include "sprite.h"
  33. #include "tcpTimer.h"
  34. #include "socket.h"
  35. #include "list.h"
  36. #include "netInet.h"
  37.  
  38.  
  39. /*
  40.  * Define the default maximum segment size to be the size of a default
  41.  * IP segment, minus the header.  On the local net we can make it bigger.
  42.  */
  43. #define TCP_MAX_SEG_SIZE    (NET_IP_MAX_SEG_SIZE - sizeof(Net_TCPHeader))
  44.  
  45. extern int        tcpISS;        /* Initial Send sequence #. */
  46. extern int        tcpKeepLen;    /* Size of data for keep-alive
  47.                      * packets. */
  48.  
  49. /* data structures */
  50.  
  51. /*
  52.  * The various states of the TCP finite state machine.
  53.  * The names are taken from RFC 793, p. 21-2.
  54.  */
  55. typedef enum {
  56.     /* These states are used before a conection is established. */
  57.     CLOSED,        /* Not connected. */
  58.     LISTEN,        /* Waiting for a connection from a remote TCP. */
  59.     SYN_SENT,    /* Have sent a SYN, waiting for reply.  */
  60.     SYN_RECEIVED,    /* Waiting for ACK of our connect request,
  61.              * have ACK'ed the remote's request. */
  62.  
  63.     ESTABLISHED,    /* An open connection -- data can be sent
  64.              * and received. */
  65.  
  66.     /* The remote TCP has closed the connection. */
  67.     CLOSE_WAIT,    /* Got a close request from the remote TCP.
  68.              * Now waiting for the User to close the connection. */
  69.     LAST_ACK,    /* Waiting for the remote TCP to ACK our FIN. */
  70.  
  71.     /* The user has closed the connection. */
  72.     FIN_WAIT_1,    /* User has closed the connection. Have sent a FIN
  73.              * to the remote TCP, waiting for the ACK. */
  74.     FIN_WAIT_2,    /* Got the ACK of our FIN, waiting for the remote
  75.              * TCP's FIN. */
  76.     CLOSING,    /* Got a FIN from the remote TCP, but still waiting
  77.              * for ACK of our FIN. */
  78.  
  79.     TIME_WAIT    /* Waiting for enough time to pass to be sure that
  80.              * the remote TCP received our ACK of its FIN. */
  81. } TCPState;
  82.  
  83. #define TCP_HAVE_RECVD_SYN(state) ((int)state >= (int)SYN_RECEIVED)
  84. #define TCP_UNSYNCHRONIZED(state) ((int)state < (int)ESTABLISHED)
  85. #define TCP_HAVE_RECVD_FIN(state) (state == TIME_WAIT)
  86. #define TCP_HAVE_SENT_FIN(state) ((int)state > (int)CLOSE_WAIT)
  87.  
  88.  
  89. /*
  90.  * From RFC 793, p. 24:
  91.  * "[...] every byte of data sent over a TCP connection has a sequence number."
  92.  * "The sequence number space ranges from 0 to 2**32 -1. Since
  93.  * this space if finite, all arithmetic dealing with sequence numbers
  94.  * must be performed modulo 2**32 [... to preserve] the relationship of
  95.  * sequence numbers as they cycle from 2**32-1 to 0 again."
  96.  */
  97.  
  98. typedef unsigned int TCPSeqNum;
  99.  
  100. #define TCP_SEQ_LT(a, b)    ((int) ((a) - (b)) < 0)
  101. #define TCP_SEQ_LE(a, b)    ((int) ((a) - (b)) <= 0)
  102. #define TCP_SEQ_GT(a, b)    ((int) ((a) - (b)) > 0)
  103. #define TCP_SEQ_GE(a, b)    ((int) ((a) - (b)) >= 0)
  104.  
  105. /*
  106.  * Macros to initialize TCP sequence numbers for send and receive from
  107.  * initial send and receive sequence numbers.
  108.  *
  109.  * TCP_INIT_SEND_SEQ_INCR is the increment added to the initial send
  110.  * sequence number every second.
  111.  */
  112.  
  113. #define TCP_RECV_SEQ_INIT(tcpPtr) \
  114.     (tcpPtr)->recv.advtWindow = (tcpPtr)->recv.next = (tcpPtr)->recv.initial+1
  115.  
  116. #define TCP_SEND_SEQ_INIT(tcpPtr) \
  117.     (tcpPtr)->send.unAck = (tcpPtr)->send.next = (tcpPtr)->send.maxSent = \
  118.     (tcpPtr)->send.urgentPtr = (tcpPtr)->send.initial
  119.  
  120. #define TCP_INIT_SEND_SEQ_INCR    (125 * 1024)
  121.  
  122.  
  123. /*
  124.  * Information about TCP connection attempts from remote hosts. This info
  125.  * is used accept or reject such connections. The queue length is increased
  126.  * by 1 because circular queues waste 1 slot in order to tell if the
  127.  * queue is full or not.
  128.  */
  129.  
  130. #define TCP_MAX_NUM_CONNECTS    5
  131. typedef struct {
  132.     int        maxQueueSize;
  133.     int        head;
  134.     int        tail;
  135.     Sock_InfoPtr    queue[1 + TCP_MAX_NUM_CONNECTS];
  136. } TCPConnectInfo;
  137.  
  138.  
  139. /*
  140.  * Information used to manage TCP data flow to and from remote hosts.
  141.  */
  142.  
  143. typedef struct {
  144.     List_Links    reassList;        /* Segment reassembly list. */
  145.     Net_TCPHeader *templatePtr;        /* Output header template. */
  146.     Net_IPHeader *IPTemplatePtr;    /* IP output header template. */
  147.     TCPConnectInfo *connectPtr;        /* Waiting connection attempts. */
  148.     TCPState    state;            /* State of this connection. */
  149.     int        flags;            /* Defined below. */
  150.     int        timer[TCP_NUM_TIMERS];
  151.     int        rxtshift;        /* Log(2) of retransmit exp. backoff. */
  152.     int        rxtcur;            /* Current retransmit value. */
  153.     int        dupAcks;        /* Consecutive dupl. acks received. */
  154.     int        maxSegSize;        /* Max. segment size. */
  155.  
  156.     /* Transmit timing: */
  157.     int        idle;            /* Inactivity timer. */
  158.     int        rtt;            /* Round-trip time. */
  159.     int        srtt;            /* Smoothed round-trip time. It is
  160.                      * fixed-point with the low-order 3 bits
  161.                      * containing the fraction. */
  162.     int        rttvar;            /* Round-trip time "variance" (actually
  163.                      * a smoothed difference). It is
  164.                      * fixed-point w/ low-order 2 bits
  165.                      * containing the fraction. */
  166.     TCPSeqNum    rtseq;            /* Seq. # used to measure RTT */
  167.  
  168.     char    urgentData;        /* The urgent data octest */
  169.     int        urgentBufPos;        /* Logical location of urgent data in
  170.                      * the receive buffer. */
  171.     Boolean    force;            /* TRUE if forcing out a byte. */
  172.  
  173.     struct {            /* send sequence variables. */
  174.     TCPSeqNum    unAck;        /* oldest acknowledged seq # (snd_una)*/
  175.     TCPSeqNum    next;        /* next seq. # to be sent. (snd_nxt) */
  176.     TCPSeqNum    window;        /* send window size. (snd_wnd) */
  177.     TCPSeqNum    urgentPtr;    /* urgent data offset. (snd_up) */
  178.     TCPSeqNum    updateSeqNum;    /* seq. # use for last window update.
  179.                      * (snd_wl1) */
  180.     TCPSeqNum    updateAckNum;    /* ack # used for last window update.
  181.                      * (snd_wl2) */
  182.     TCPSeqNum    initial;    /* initial seq # sent on SYN packets.
  183.                      * (iss) */
  184.     TCPSeqNum    maxSent;    /* highest seq. # sent, used to
  185.                      * recognize retransmits. (snd_max) */
  186.     unsigned int    congWindow;    /* congestion-controlled window.
  187.                      * (snd_cwnd) */
  188.     unsigned int    cwSizeThresh;    /* congWindow size threshold for
  189.                      * slow start exponential to linear
  190.                      * switch. (snd_ssthresh) */
  191.     int        maxWindow;    /* largest window size the peer
  192.                      * has offered. (max_sndwnd) */
  193.     } send;
  194.  
  195.     struct {            /* receive sequence variables. */
  196.     TCPSeqNum    next;        /* next seq. # expected on incoming
  197.                      * packets. (rcv_nxt) */
  198.     TCPSeqNum    window;        /* recv. window size. (rcv_wnd) */
  199.     TCPSeqNum    urgentPtr;    /* urgent data offset. (rcv_up) */
  200.     TCPSeqNum    initial;    /* initial seq # from peer's SYN
  201.                      * packet. (irs) */
  202.     TCPSeqNum    advtWindow;    /* advertised window size. (rcv_adv) */
  203.     int        maxWindow;    /* largest amount the peer has sent
  204.                      *  into a window. (max_rcvd) */
  205.     } recv;
  206. } TCPControlBlock;
  207.  
  208. /*
  209.  * Definitions of "flags" in the TCP_ControlInfo struct.
  210.  *
  211.  *    TCP_ACK_NOW        - ACK the peer immediately.
  212.  *    TCP_DELAY_ACK        - do an ACK, but try to delay it.
  213.  *    TCP_NO_DELAY        - don't delay packets in order to coalesce.
  214.  *    TCP_IGNORE_OPTS        - don't use the options.
  215.  *    TCP_SENT_FIN        - a FIN has been sent.
  216.  *    TCP_HAVE_URGENT_DATA    - urgent data is ready to be read.
  217.  *    TCP_HAD_URGENT_DATA    - urgent data has been read.
  218.  */
  219.  
  220. #define TCP_ACK_NOW        0x01
  221. #define TCP_DELAY_ACK        0x02
  222. #define TCP_NO_DELAY        0x04
  223. #define TCP_IGNORE_OPTS        0x08
  224. #define TCP_SENT_FIN        0x10
  225. #define TCP_HAVE_URGENT_DATA    0x20
  226. #define TCP_HAD_URGENT_DATA    0x40
  227.  
  228.  
  229. /*
  230.  * Commands for TCPTrace().
  231.  */
  232.  
  233. typedef enum {
  234.     TCP_TRACE_INPUT,
  235.     TCP_TRACE_OUTPUT,
  236.     TCP_TRACE_RESPOND,
  237.     TCP_TRACE_DROP,
  238. } TCPTraceCmd;
  239.  
  240.  
  241. /* procedures */
  242.  
  243. extern void        TCPTrace();
  244. extern void        TCPCloseConnection();
  245. extern void        TCPDropConnection();
  246. extern void        TCPCancelTimers();
  247. extern void        TCPRespond();
  248. extern void        TCPMakeTemplateHdr();
  249. extern ReturnStatus    TCPOutput();
  250. extern TCPControlBlock    *TCPSocketToTCB();
  251. extern TCPControlBlock    *TCPReassemble();
  252. extern Sock_InfoPtr    TCPCloneConnection();
  253. extern TCPControlBlock    *TCPSockToTCB();
  254. extern int        TCPCalcMaxSegSize();
  255. extern void        TCPCleanReassList();
  256. extern void        TCPPrintHdrFlags();
  257. extern void        TCPTimerInit();
  258. extern void        TCPSetPersist();
  259.  
  260. #endif /* _IPS_TCPINT */
  261.